#include<bits/stdc++.h>
using namespace std;
int n;
vector<int>v[100005];
priority_queue<pair<int,int> >up[100005];
int maxx[100005];
int id[100005];
int ans;
void dfs(int x,int fa)
{
    id[x]=x;
    for(int i=v[x].size()-1;i>=0;i--)
    {
        int xx=v[x][i];
        if(xx==fa)
        {
            continue;
        }
        dfs(xx,x);
        if(up[id[xx]].size()>up[id[x]].size())
        {
            while(!up[id[x]].empty())
            {
                up[id[xx]].push(up[id[x]].top());
                up[id[x]].pop();
            }
            id[x]=id[xx];
        }
        else
        {
            while(!up[id[xx]].empty())
            {
                up[id[x]].push(up[id[xx]].top());
                up[id[xx]].pop();
            }
        }
        maxx[x]=max(maxx[x],maxx[xx]);
    }
    if(up[id[x]].size()==0)
    {
        up[id[x]].push(make_pair(1,0));
    }
    else if(up[id[x]].size()==1)
    {
        pair<int,int>now=up[id[x]].top();
        up[id[x]].pop();
        up[id[x]].push(make_pair(1,0));
        now.second=1;
        up[id[x]].push(now);
    }
    else
    {
        int flag=0;
        int t1=up[id[x]].top().first;
        if(up[id[x]].top().second==1)
        {
            flag=1;
        }
        up[id[x]].pop();
        int t2=up[id[x]].top().first;
        if(up[id[x]].top().second==1)
        {
            flag=1;
        }
        up[id[x]].pop();
        up[id[x]].push(make_pair(t1+t2+1,flag));
    }
    if(up[id[x]].size()==1)
    {
        pair<int,int>now=up[id[x]].top();
        up[id[x]].pop();
        now.second=0;
        up[id[x]].push(now);
    }
}
int main()
{
    freopen("bird1.in","r",stdin);
    //freopen("bird.out","w",stdout);
    cin>>n;
    int s,t;
    for(int i=1;i<n;i++)
    {
        cin>>s>>t;
        v[s].push_back(t);
        v[t].push_back(s);
    }
    dfs(1,0);
    cout<<up[id[1]].top().first+up[id[1]].top().second;
    return 0;
}
